﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Marksona", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(Marksona))]
    public class MarksonaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMarksona clazz;
        
        public MarksonaSerializer(IMarksona clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.ObjektID!=null) {
                Writer.WriteStartElement("ObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Alustaja!=null) {
                Writer.WriteStartElement("Alustaja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Alustaja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKP!=null) {
                Writer.WriteStartElement("LoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.LoppKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Lopetaja!=null) {
                Writer.WriteStartElement("Lopetaja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Lopetaja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SulgemiseKP!=null) {
                Writer.WriteStartElement("SulgemiseKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.SulgemiseKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.JrkNrHarus!=null) {
                Writer.WriteStartElement("JrkNrHarus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.JrkNrHarus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Vaartus!=null) {
                Writer.WriteStartElement("Vaartus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Vaartus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlamMarksonad!=null) {
                Writer.WriteStartElement("AlamMarksonad");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("Marksona", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.AlamMarksonad.Count);
                for (int x = 0; ((clazz.AlamMarksonad != null) 
                            && (x < clazz.AlamMarksonad.Count)); x = (x + 1)) {
                    if (clazz.AlamMarksonad[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaAlamMarksonad = this.GetMetaData(clazz.AlamMarksonad[x]);
                        Writer.WriteTypeAttribute(metaAlamMarksonad.TypeQualifiedName.Namespace, metaAlamMarksonad.TypeQualifiedName.Name);
                        metaAlamMarksonad.NewSerializer(clazz.AlamMarksonad[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.AsendatavadMarksonad!=null) {
                Writer.WriteStartElement("AsendatavadMarksonad");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("Marksona", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.AsendatavadMarksonad.Count);
                for (int x = 0; ((clazz.AsendatavadMarksonad != null) 
                            && (x < clazz.AsendatavadMarksonad.Count)); x = (x + 1)) {
                    if (clazz.AsendatavadMarksonad[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaAsendatavadMarksonad = this.GetMetaData(clazz.AsendatavadMarksonad[x]);
                        Writer.WriteTypeAttribute(metaAsendatavadMarksonad.TypeQualifiedName.Namespace, metaAsendatavadMarksonad.TypeQualifiedName.Name);
                        metaAsendatavadMarksonad.NewSerializer(clazz.AsendatavadMarksonad[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Marksona>ObjektID");
                }
                clazz.ObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ObjektID")).Value;
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Alustaja") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Alustaja = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Alustaja")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("LoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Lopetaja") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Lopetaja = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Lopetaja")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SulgemiseKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SulgemiseKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("SulgemiseKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="JrkNrHarus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Marksona>JrkNrHarus");
                }
                clazz.JrkNrHarus = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("JrkNrHarus")).Value;
            }
            if (Reader.LocalName=="Vaartus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Vaartus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Vaartus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AlamMarksonad") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlamMarksonad = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("AlamMarksonad");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaAlamMarksonad = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona>(Reader, "Marksona", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona item = metaAlamMarksonad.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona>();
                                clazz.AlamMarksonad.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaAlamMarksonad.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.AlamMarksonad.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsendatavadMarksonad") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsendatavadMarksonad = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("AsendatavadMarksonad");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaAsendatavadMarksonad = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona>(Reader, "Marksona", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona item = metaAsendatavadMarksonad.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMarksona>();
                                clazz.AsendatavadMarksonad.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaAsendatavadMarksonad.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.AsendatavadMarksonad.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
